package com.xhtt.modules.app.controller.sys;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xhtt.common.exception.RRException;
import com.xhtt.common.exception.RRExceptionEnum;
import com.xhtt.common.utils.Constant;
import com.xhtt.common.utils.ExportExcel;
import com.xhtt.common.utils.PageUtils;
import com.xhtt.common.utils.R;
import com.xhtt.modules.app.annotation.Login;
import com.xhtt.modules.cfg.entity.CfgHoseInfo;
import com.xhtt.modules.sys.controller.AbstractController;
import com.xhtt.modules.sys.service.SysUserAppLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * app登陆记录 前端控制器
 * </p>
 *
 * @author feipc
 * @since 2019-05-30
 */
@Api(tags = "app登陆记录列表", value = "app登陆记录列表")
@RestController
@RequestMapping("app/sys/user/applog")
public class SysUserAppLogController extends AbstractController {

    @Autowired
    private SysUserAppLogService sysUserAppLogService;

    /**
     * 获取app登陆记录列表
     */
    @GetMapping(value = "/logList")
    @ApiOperation("获取app登陆记录列表")
    @Login
    public R logList(@RequestParam Map<String, Object> params) {
        PageUtils page = sysUserAppLogService.logList(params);
        return R.ok().put(Constant.DATA, page);
    }

    @GetMapping(value = "/logExport")
    @ApiOperation("app登陆记录导出")
    @Login
    public void logExport(HttpServletResponse response, @RequestParam Map<String, Object> params) {
        ExportExcel exportExcel = new ExportExcel();
        PageUtils page = sysUserAppLogService.logList(params);
        List list = page.getList();
        String fileName = "app登陆记录";
        String sheetName = "app登陆记录";
        String[] headers = {"用户名", "部门", "分组", "PAD编号", "登录时间"};
        String[] columns = {"name", "deptName", "teamName", "padNo", "loginDate_f"};
        try {
            exportExcel.exportExcel(fileName, sheetName, headers, columns, list, response);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RRException(RRExceptionEnum.EXPORT_FAIL);
        }
    }
}
